* Nybom and Stuhler, Interpreting Trends in Intergenerational Mobility - Figure A3
* An increase in the returns to a single skill, with sibling correlation

cd "/Users/janstuhler/Dropbox/MartinJanProjects/Trend_Project/Submissions/JPE/Final version/Simulations/Figure A3"

clear
set more off
   
* Input transition paths (computed in Excel file "FigureA3.xlsx")
input country period str18 periodlabel igc ige var_y sib 
1 1 ""      0.572	0.572	1.331	0.581
1 2 ""  	0.572	0.572	1.331	0.581
1 3 "T"     0.509	0.608	1.901	0.443
1 4 ""      0.539	0.549	1.971	0.463 
1 5 ""  	0.539	0.539	1.977	0.464
                        
2 1 "T-2"   0.411	0.411	0.857	0.487  
2 2 ""  	0.411	0.411	0.857	0.487
2 3 "T"     0.362	0.467	1.426	0.341
2 4 ""      0.434	0.445	1.497	0.372
2 5 ""  	0.437	0.437	1.503	0.374 
end

* Generate variance income in previous generation, and average of variance in current and previous generation
sort country period
by country: gen var_y_m1 = var_y[_n-1]
replace var_y_m1 = var_y if var_y_m1==.
by country: gen var_y_mix = (1/2)*(var_y+var_y[_n-1])
replace var_y_mix = var_y if var_y_mix==.

* Plot Great-Gatsby IGE-Variance(mixed)
/*local l1 = "mlabel(periodlabel)  mlabp(6) mlabgap(*2.5) mcolor(black) msize(small) mlabcolor(black)"
twoway  (connected ige var_y_mix if country==1 & period>1 , lwidth(thin) lpattern(solid) lcolor(black) msymbol(D) `l1') ///
		(connected igc var_y_mix if country==1 & period>1 , lwidth(thin) lpattern(shortdash) lcolor(black) msymbol(D) `l1') ///
		(connected ige var_y_mix if country==2 & period>1 , lwidth(thin) lpattern(solid) lcolor(black) msymbol(T) `l1') ///
		(connected igc var_y_mix if country==2 & period>1 , lwidth(thin) lpattern(shortdash) lcolor(black) msymbol(T) `l1') ///	
		(line ige var_y_mix if country==1 & period>1 , lwidth(thin) lpattern(solid) lcolor(black)) ///
		(line ige var_y_mix if country==2 & period>1 , lwidth(thin) lpattern(shortdash) lcolor(black)) ///
		, scheme(economist) xlabel(none) yscale(range(0.3(0.05)0.66)) xscale(range(0.4(0.05)2.25)) ylabel(none) xsize(4) ysize(4)  ///
		xtitle("Income Variance") ytitle("Intergenerational Persistence") graphregion(color(white)) ///
		legend(lab(5 "Elasticity") lab(6 "Correlation") order(5 6) fcolor(white) size(medsmall) bplacement(north) region(color(white))) ///
		yscale(axis(1) alt on lwidth(thin) lcolor(black)  titlegap(*5)) ///
		xscale(axis(1) lwidth(thin) lcolor(black)  titlegap(*5))   /// 
		text(0.451 0.76 "Country A" , box lcolor(ebackground) lwidth(none) bmargin(vlarge)) ///
		text(0.396 0.80 "Old S-S" ,size(small)) ///
		text(0.439 1.67 "New S-S" ,size(small)) ///
		text(0.416 1.46 "T+1" ,size(small)) ///
		text(0.612 1.28 "Country B" , box lcolor(ebackground) lwidth(none) bmargin(vlarge)) /// 
		text(0.555 1.25 "Old S-S" ,size(small)) ///
		text(0.539 2.14 "New S-S" ,size(small)) ///
		text(0.525 1.93 "T+1" ,size(small)) 
	
		graph export "Great_Gatsby_New.eps" , replace 
		graph export "Great_Gatsby_New_Times.eps" , replace fontface("Times-Roman") */

	
* Plot Great-Gatsby IGE-Variance(with sibling correlation)
local l1 = "mlabp(6) mlabgap(*2.5) mcolor(black) msize(small) mlabcolor(black)"
twoway	(connected ige var_y_mix if country==2 & period>1 , lwidth(thin) lpattern(solid) lcolor(black) msymbol(T) `l1') ///
		(connected igc var_y_mix if country==2 & period>1 , lwidth(thin) lpattern(shortdash) lcolor(black) msymbol(T)  `l1') ///
		(connected sib var_y_mix if country==2 & period>1 , lwidth(thin) lpattern(solid) lcolor(black) msymbol(C) mlabel(periodlabel)  `l1') ///	
		(line ige var_y_mix if country==2 & period>1 , lwidth(thin) lpattern(shortdash) lcolor(black)) ///
		, scheme(economist) xlabel(none) yscale(range(0.28(0.05)0.53)) xscale(range(0.55(0.05)1.8)) ylabel(none) xsize(4) ysize(4)  ///
		xtitle("Income Variance") ytitle("Intergen. Persistence / Sibling Correlation") graphregion(color(white)) ///
		legend(lab(1 "Elasticity") lab(2 "Int. Corr") lab(3 "Sib. Corr.") order(1 2 3) fcolor(white) size(medsmall) bplacement(north) region(color(white))) ///
		yscale(axis(1) alt on lwidth(thin) lcolor(black)  titlegap(*5)) ///
		xscale(axis(1) lwidth(thin) lcolor(black)  titlegap(*5))   /// 
		text(0.450 0.79 "Old S-S" ,size(small)) ///
		text(0.403 1.63 "New S-S" ,size(small)) ///
		text(0.360 1.46 "T+1" ,size(small)) 
	
		graph export "Great_Gatsby_withsib_New.eps" , replace 
		graph export "Great_Gatsby_withsib_New_Times.eps" , replace fontface("Times-Roman") 


exit








